package com.harry.hr.utils;


import java.lang.reflect.Method;
import java.sql.Date;



public class FillEntityUtil {
	
	
    public static Object fillEntityUtil(Object clientVo, Object serverVo) throws Exception 
    { 
    	
        //通过反射得出客户端vo的所有get的属性方法 
        Class<?> clientClass = clientVo.getClass(); 
        System.out.println(clientClass.toString());
        Method[] methods = clientClass.getMethods(); 
        for(int i = 0; i < methods.length; i++) 
         { 
           // System.out.println(methods[i].getName()); 
            String methodName = methods[i].getName(); 	
            //查找出set相关的方法 
            int isGet = methodName.indexOf("get"); 
            //int isHufId=methodName.indexOf("HufId");
                 
            if(isGet != -1 && !methodName.equals("getClass")&&methods[i].invoke(serverVo, null)==null) 
            {
            	//System.out.println(methods[i].invoke(serverVo, null));
            	
                Object result = null; 
                //反射出该方法，并得到它的返回结果 
                try { 
                    result = methods[i].invoke(clientVo,null); 
               
	                //System.out.println("===result===:" + result); 
	                if(result != null){ 
		                    //有值，则传给serverVo对应的set方法 
		                    methodName = methodName.substring(3,methodName.length()); 
		                    //System.out.println("==result.getClass()===" + result.getClass()); 
		                    if(result.getClass() == Integer.class||result.getClass() == Double.class||
		                       result.getClass() == Boolean.class||result.getClass() == Short.class||
		                       result.getClass()==java.util.Date.class||
		                       result.getClass()==java.lang.String.class){
		                    	
			                   Method method = null; 
			                   method = serverVo.getClass().getMethod("set" + methodName,result.getClass()); 
			                   //System.out.println("==method===" + method); 
			                    
			                   method.invoke(serverVo,result); 
		                        }
		                        //System.out.println("=newResult====" + newResult); 
	                     }
                 }catch(Exception e)  { 
                        e.printStackTrace(); 
                    } 
                }
        } 
        return serverVo;
    } 


}